import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { externalDeps, globalVarMap, cssOptimization } from './build.config'

// For simple build, we only export the standalone version
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    dts({
      insertTypesEntry: true,
      copyDtsFiles: false,
      outDir: 'dist/simple',
      staticImport: true
    })
  ],
  css: cssOptimization,
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index-simple.ts'),
      name: 'EpmsElementSimple',
      fileName: (format) => `index.${format === 'es' ? 'mjs' : 'js'}`
    },
    rollupOptions: {
      external: externalDeps,
      output: {
        exports: 'named',
        globals: globalVarMap,
        inlineDynamicImports: false,
        preserveModules: true,
        preserveModulesRoot: 'src',
        dir: 'dist/simple'
      }
    },
    cssCodeSplit: false,
    sourcemap: true,
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: false,
        drop_debugger: true
      }
    },
    outDir: 'dist/simple'
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  define: {
    __VUE_OPTIONS_API__: true,
    __VUE_PROD_DEVTOOLS__: false
  }
}) 